
package com.viweb.storemanager.temp;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import javax.swing.JRadioButton;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import sun.swing.DefaultLookup;


public class RadioButtonListCellRenderer extends JRadioButton
        implements ListCellRenderer {

    private Color oddLine = new Color(240, 240, 255);
    private Color evenLine = Color.WHITE;
    private Color selectedLine = new Color(172, 210, 255);
    private Border noFocusBorder = new EmptyBorder(1, 1, 1, 1);

    public RadioButtonListCellRenderer() {
        super();
    }

    public Component getListCellRendererComponent(
            JList list, Object value, int index,
            boolean isSelected, boolean hasFocus) {

        if (isSelected) {
            this.setBackground(this.selectedLine);
        } else {
            if (index % 2 == 0) {
                this.setBackground(this.evenLine);
            } else {
                this.setBackground(this.oddLine);
            }
        }

        Border border = null;
        if (hasFocus) {
            if (isSelected) {
                border = DefaultLookup.getBorder(this, ui, "List.focusSelectedCellHighlightBorder");
            }
            if (border == null) {
                border = DefaultLookup.getBorder(this, ui, "List.focusCellHighlightBorder");
            }
        } else {
            border = noFocusBorder;
        }
        this.setBorder(border);

        this.setEnabled(list.isEnabled());
        Dimension size = new Dimension(this.getPreferredSize().width, list.getFixedCellHeight());
        this.setPreferredSize(size);
        this.setFont(list.getFont());
        this.setForeground(Color.BLACK);
        this.setSelected(isSelected);
        if (value != null) {
            this.setText(" " + value.toString() + " ");
        } else {
            this.setText(null);
        }

        return this;
    }
}

